#include "common.hpp"

int main()
{
    // 客户端写数据，服务端接收

    cout << "opening..." << endl;
    int wrd = open(NAMED_PIPE, O_WRONLY);
    cout << "opened" << endl;

    if(wrd < 0) 
    {
        cerr << "errno : " << errno << " strmsg : "<< strerror(errno) << endl;
        exit(1);
    }

    while(true)
    {
        cout << "please say# : ";

        char buffer[1024];
        fgets(buffer, sizeof(buffer) + 1, stdin);
        if(strlen(buffer) > 0) buffer[strlen(buffer) - 1] = '\0';

        ssize_t s = write(wrd, buffer, strlen(buffer));
        assert(s == strlen(buffer));
        (void)s;
    }


    return 0;
}